// pages/distribut/sotre-close/store_close.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../utils/common.js');
var util = require('../../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		from:{
			start_time: '',
			end_time: '',
			reason_id:''
		},
		text:'请选择',
		list: [],
		textlist: []
	},
	bindDateChange: function(e) {
		this.setData({
			'from.start_time': e.detail.value
		})
	},
	bindDateChange1: function(e) {
		this.setData({
			'from.end_time': e.detail.value
		})
	},
	// 提交申请
	submit(){
		console.log(this.data.from)
		let that = this
		let data={...this.data.from}
		data.apply_id=data.id
		let dataurl=data.id?'/api/shop/restApplyEdit':'/api/shop/restApply'
			request.post(dataurl, {
				data:data,
				success: function(res) {
					if (res.data.status == 1) {
						wx.showToast({
							  title: '歇业申请已提交'
							})
						let pages = getCurrentPages();   //获取小程序页面栈
						    let beforePage = pages[pages.length -2];  //获取上个页面的实例对象
						   
						    beforePage.getinfo();   //触发上个页面自定义的go_update方法
						    wx.navigateBack({         //返回上一页  
						      delta:1
						    })
					}
				}
			});
		
	
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.getlist()
		this.getinfo()
	},
	// 选择歇业原因
	bindDate(e) {
		let text=this.data.list[parseInt(e.detail.value)].title
		this.setData({
			value:e.detail.value,
			'from.reason_id': this.data.list[parseInt(e.detail.value)].id,
			'from.reason_text':text,
			text:text
		})
	},
	// 歇业详情
	getinfo() {
		let that = this
		request.get('/api/shop/restApplyInfo', {
			success: function(res) {
				if (res.data.status == 1&&res.data.result&&res.data.result.status!=2 ) {
					res.data.result.end_time=util.format(res.data.result.end_time, 'yyyy-MM-dd');
					res.data.result.start_time=util.format(res.data.result.start_time, 'yyyy-MM-dd');
					that.setData({
						from: res.data.result,
						text:res.data.result.reason_text
					});
				}
			}
		});
	},
	// 歇业原因列表
	getlist() {
		let that = this
		request.get('/api/shop/restReasonList', {
			success: function(res) {
				if (res.data.status == 1) {
					let datlist = []
					res.data.result.forEach(e => {
						datlist.push(e.title)
					})
					that.setData({
						list: res.data.result,
						textlist: datlist
					});
				}
			}
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})